﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using System.Data;

namespace Honestysoft.Financing.WebUI.Module.Project
{
    public partial class ProjectOverview_List : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                AspNetPager1.PageSize = Globals.PageSize;
                BindControl();
                Bind();
            }
        }
        /// <summary>
        /// 绑定页面控件。
        /// </summary>
        private void BindControl()
        {
            ControlHelper.BindDictionary(ddlProjectCategory, "ProjectCategory");
            ControlHelper.InsertAllItemAndSelect(ref ddlProjectCategory);
        }
        /// <summary>
        /// 设置弹出窗体大小
        /// 基类中已自动做控制。默认宽度800，高度600
        /// </summary>
        protected override void SetDialogSize()
        {
            ////base.SetDialogSize();
            ////重载宽度，高度
            //ModalDialogSize.EditHeight = 700;
            //ModalDialogSize.EditWidth = 900;
            //ModalDialogSize.ViewHeight = 700;
            //ModalDialogSize.ViewWidth = 900;
        }

        protected string GetEditUrl(string subject, string id,string sn)
        {
            string url = "";//openwindow(url, name)
            url += "<a href=\"#\" onclick=\"openwindow('" + Globals.Home + "Module/Project/ProjectOverview.aspx?ID=" + id + "&edit=" + (PageSecurity.Edit ? "true" : "false") + "&FunctionID=" + FunctionID + "&SN=" + sn + "&Name=" + Server.UrlEncode(subject) + "', '" + (PageSecurity.Edit ? "修改" : "查看") + "项目简介');\">" + subject + "</a>";
            return url;
        }

        /// <summary>
        /// 根据权限控制页面按钮.
        /// 基类中已自动做控制。
        /// </summary>
        protected override void ButtonSetting()
        {
            //base.ButtonSetting();
        }
        /// <summary>
        /// 绑定列表
        /// </summary>
        private void Bind()
        {
            string owner971 = "";
            if (ddlProjectCategory.SelectedValue != "0")
            {
                owner971 = ddlProjectCategory.SelectedValue;
            }
            int recordCount = 0, pageCount = 0;
            DataTable dtProject = new Honestysoft.Financing.BusinessLogic.Project(Globals.CurrentConnStringName).QueryProjectOverview(txtSN.Text.Trim(), owner971, txtName.Text.Trim(), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex,out pageCount, out recordCount);
            AspNetPager1.RecordCount = recordCount;
            rptList.DataSource = dtProject;
            rptList.DataBind();
        }

        /// <summary>
        /// 得到表格行操作按钮脚本
        /// </summary>
        /// <param name="dataId">记录ID</param>
        /// <param name="sn"></param>
        /// <param name="name"></param>
        /// <returns>操作按钮脚本</returns>
        protected string GetButtonScript(string dataId,string sn,string name)
        {
            //url += "<a href=\"#\" onclick=\"openwindow('" + Globals.Home + "Module/Project/ProjectOverview.aspx?ID=" + id + "&FunctionID=" + FunctionID + "', '修改项目简介');\">" + subject + "</a>";

            //string script = ScriptHelper.LinkButton.GetGridEditButton(Globals.Home + "Module/Project/ProjectOverview.aspx", "修改项目信息", ModalDialogSize.EditWidth, ModalDialogSize.EditHeight, dataId, FunctionID);
            string script = "";
            if (PageSecurity.Edit)
            {
                script = ScriptHelper.LinkButton.GetGridImageButton("openwindow('" + Globals.Home + "Module/Project/ProjectOverview.aspx?ID=" + dataId + "&edit=true&FunctionID=" + FunctionID + "&SN=" + sn + "&Name=" + Server.UrlEncode(name) + "', '修改项目简介');", ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit), "修改项目简介", "");
            }
            else
            {
                script = ScriptHelper.LinkButton.GetGridImageButton("openwindow('" + Globals.Home + "Module/Project/ProjectOverview.aspx?ID=" + dataId + "&edit=false&FunctionID=" + FunctionID + "&SN=" + sn + "&Name=" + Server.UrlEncode(name) + "', '修改项目简介');", ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.View), "查看项目简介", "");
            }
            return script;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}